#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
# @Time    : 2024/6/14 17:02
# @Author  : YangYong
# @File    : process_variables_view.py
# @describe: 获取流程的变量
"""
from flask import request

from apis.flow import flow_ns
from apis.flow.schema.variable_config_schema import ProcessVariableSchema
from apis.orderlines.models import Variable
from public.base_model import db
from public.base_response import generate_response
from public.api_utils.api_decorator import handle_api_error
from public.base_view import AbstractView


class ProcessVariableView(AbstractView):
    url = '/process_variable'

    def __init__(self, *args, **kwargs):
        super(ProcessVariableView, self).__init__(*args, **kwargs)
        self.form_data: dict = request.args or {}
        self.process_id = self.form_data.get('process_id')

    @handle_api_error()
    @flow_ns.doc(description='获取流程变量')
    def get(self):
        """获取流程变量"""
        objs = db.session.query(Variable).filter(Variable.process_id == self.process_id, Variable.active == 1).all()
        process_variables = ProcessVariableSchema().dump(objs, many=True)
        return generate_response(process_variables)
